package Thread;

import com.sun.deploy.ui.ImageLoader;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
interface q1{
    BlockingDeque<Integer> deque = new LinkedBlockingDeque<>();
}
//消费者
class MyThread2 extends Thread implements q1{
    @Override
    public void run() {
        while (true){
            try {
                System.out.println("消费者元素: "+deque.take());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
//生产者
class MyThread3 extends Thread implements q1{
    @Override
    public void run() {
        int value = 0;
        while (true){
            try {
                System.out.println("生产元素: "+value);
                deque.put(value++);
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
public class ThreadDemo16 {
    public static void main(String[] args) {
        //消费者
        Thread t1 = new MyThread2();
        //生产者
        Thread t2 = new MyThread3();
        t1.start();
        t2.start();
    }
}
